Help:Semantic templates
Semantic templates are a method of including the markup that Semantic MediaWiki introduces through MediaWiki templates. This has several advantages: * users can specify annotations without learning any new syntax * annotations are used consistently, i.e. users do not have to look for the right properties or categories when editing a page * infobox-style templates provide data structure, by defining which values belong in which pages * infobox-style templates also often provide a nice display for the data For these reasons, semantic templates are a very popular way of handling semantic annotations. In most wikis, semantic data is stored only via templates - in fact, we would estimate that 99% of all SMW data that currently exists is stored via a template. Even SMW-based extensions meant to make free-form SMW annotations easier, like Halo, do it within the context of a system in which data is also stored using templates. Infobox-style semantic templates Many MediaWiki sites, SMW-based and otherwise, make use of infobox-style templates to present standard information. For example, Wikipedia articles on cities and villages use a standard template in which editors specify common items of information, such as this (from the article "San Diego, California"): and the template expands to your desired markup. To achieve this, template "Surface area" is coded as follows: } × 10 } m² This template handles both storing the value semantically (via the "Surface area" property tag), and displaying it a nicely-formatted way on the screen (via everything that comes after the "|" in the tag). See the sample page Sol and view its source to see this template in use. Using semantic templates correctly While the above pattern allows you to create all kinds of semantic templates of arbitrary complexity, there are some issues to consider. Automatic annotation requires strict formats You can annotate template fields automatically, but in this case the supplied values must adhere to the expected format. For example, it makes sense to store the population of a city with a property of type . Still, the value that users enter might not be a number - it could be a piece of text like "Around 1 million". Wikipedia notably has many such exceptions: in the main infobox template at France, for instance, the entry supplied for population is not a single number, or even a set of numbers! Instead, there are multiple numbers and textual explanations of their meaning. Such special cases should be kept in mind when designing semantic templates. Optional entries and conditionals In the normal course of operating a wiki, most pages will probably not have their infoboxes completely filled, and you might not want to show empty rows in such cases. To remove rows with blank values, you can add conditionals into the template code, which include a row (and its annotation) only if a non-empty value was provided. This can be achieved with the help of the #if parser function, defined in the MediaWiki ParserFunctions extension. Wikipedia contains many examples of parser functions in templates, as for instance in template "Taxobox". Using parser functions typically results in difficult-to-read template code, but the simplification for users can be substantial. Queries in templates are sometimes added to templates as well, and they almost always contain the variable; see e.g. template "Ask". Such queries are usuallly used to aggregate a set of pages that have some property pointing to the page in question, such as the template for a country page using a query to show a list of each country's cities. Annotating a template You can also add annotations directly to templates, i.e. assign them semantic properties directly. Though this is not recommended, since templates don't represent a real-world entity, it can be done, if the site administrator enables it. Editing template calls A popular extension, Semantic Forms, lets users add and edit calls to infobox-style templates using forms. See also the . | master link = internal | status = effective | progress = 100 | priority = 2 | category = Manual | author = Markus Krötzsch | editor = | support = Markus Krötzsch | minversion = 1.0 | lang = en | desc = | return = | nowarn }}